package com.jing.cloud.service.chat.cron;

import com.alibaba.fastjson.JSONObject;
import com.jing.cloud.service.chat.adapter.MessageAdapter;
import com.jing.cloud.service.chat.adapter.MessageBean;
import com.jing.cloud.service.chat.constant.ChatConstant;
import com.jing.cloud.service.util.keygen.DefaultKeyGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by 29017 on 2017/9/12.
 */
//@Component
@Slf4j
public class MessageSendTask {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Scheduled(cron = "0/1 * * * * ?")
    public void run() {
        long now = System.currentTimeMillis();
        log.info("starting...");
        MessageBean messageBean = new MessageBean();
        messageBean.setId(DefaultKeyGenerator.getInstance().generateKey().longValue());
        messageBean.setSender(10000L);
        messageBean.setTarget(114323871003312246L);
        messageBean.setScene(ChatConstant.MESSAGE_SCENE_U2U);
        messageBean.setType(1);
        messageBean.setType2(1001);
        messageBean.setTicket("aaa");
        messageBean.setLocalId(now);
        JSONObject body = new JSONObject();
        body.put("body", sdf.format(new Date()));
        messageBean.setMessage(body);
        MessageAdapter.handleMessage(messageBean);
    }
}
